
package com.lennon.eoi.executors;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 执行框架
 * 
 * @author lennon
 * @time 2017年8月27日下午6:54:09
 *
 */
public class EOIExecutors {

	/**
	 * 线程池
	 * 
	 */
	private static ExecutorService executor = new ThreadPoolExecutor(1, 20, 0L, TimeUnit.MILLISECONDS, 
	        new LinkedBlockingQueue(), new EOIThreadFactory("EOIExecutors Thread Pool"));

	/**
	 * 线程执行器 
	 * 
	 * @param eoiTaskWrepper
	 * @param isRunnable
	 */
	public static void execute(EOITaskWrapper eoiTaskWrepper, boolean isRunnable) {
		
		// 是否提交到线程池进行处理
		if(isRunnable) {
			executor.execute(eoiTaskWrepper);
			return ;
		}
		
		eoiTaskWrepper.run();
	}
	
	public static void submit(EOITaskWrapper eoiTaskWrepper) {
		executor.submit(eoiTaskWrepper);
	}
	
	public static void shutdown() {
		executor.shutdown();
	}
	
	
	public static void shutdownNow() {
		executor.shutdownNow();
	}
	
}
